package com.criteria.filter.implextend;

import com.criteria.filter.PersonCriteria;
import com.criteria.po.Person;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

public class PersonOrCriteria implements PersonCriteria {

    private List<PersonCriteria> criteria;

    public PersonOrCriteria(PersonCriteria ... criteria) {
        this.criteria = Arrays.asList(criteria);
    }

    @Override
    public List<Person> streamFilterCollect(List<Person> persons) {
        HashSet<Person> personSet = new HashSet<>();  // 使用Set去重之前需要重写HashCode
        for ( PersonCriteria c : criteria )
            personSet.addAll(c.streamFilterCollect(persons));
        return personSet.stream().collect(Collectors.toList());
    }
}
